/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author André
 */
public class HibernateUtil {
    
    private static SessionFactory sessionFactory;
	public static SessionFactory getSessionFactory() {
		if (sessionFactory == null) {
			AnnotationConfiguration cfg = new AnnotationConfiguration();
			Configuration config = cfg.configure("hibernate/hibernate.cfg.xml");
			sessionFactory = config.buildSessionFactory();
		}
		return sessionFactory;
	}
	public static Session getSession(){
		Session sessao = getSessionFactory().openSession();
		return sessao;
	}
    
}
